// index.js

import Vue from 'vue';
import Vuex from 'vuex';
import { getMyTeamList } from "@/api/api.js"
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    teamStatus: false, //是否团队模式
    folderId: "0", // 文件夹ID
    teamList: [],// 团队列表
    addTeam: true,
    currentTeamId: null,//当前团队ID
    teamRole: "",// 团队角色
    teamCode: "",//团队code
  },
  mutations: {
    personHandel(state) {
      state.currentTeamId = null
      state.teamRole = ""
      state.teamStatus = false
      state.teamCode = ""
    },
    teamHandel(state, item) {
      console.log(item)
      state.currentTeamId = item.teamId
      state.teamRole = item.role
      state.teamStatus = true
      state.teamCode = item.code
      console.log(state.teamCode)
    },
    setFolderId(state, args) {
      state.folderId = args
    },
    // 获取我的团队列表
    getTeamList(state) {
      getMyTeamList().then(res => {
        state.teamList = res.data
        res.data.forEach(e => {
          if (e.role === 'OWNER') {
            state.addTeam = false
          }
        })
      })
    },
  },
});